#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int maxn = 1005;

set<int> G[maxn]; // 图的存储
vector<int> ans;
bool vis[maxn];

bool dfs(int u, int target) {
  if (u == target) {
    ans.push_back(u);
    return 1;
  }
  for (int son : G[u]) {
    if (vis[son])
      continue;
    vis[son] = 1;
    if (dfs(son, target)) {
      ans.push_back(u);
      return 1;
    }
  }
  return 0;
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m,x,y;
    cin >> n >> m >> x >> y;
    ans.resize(0);
    for (int i = 1; i <= n; i++) {
      G[i].clear();
      vis[i] = 0;
    }
    for (int i = 1; i <= m; i++) {
      int u, v;
      cin >> u >> v;
      G[u].insert(v);
      G[v].insert(u);
    }

    vis[x] = 1;
    dfs(x, y);
    for (int i = ans.size() - 1; i >= 0; i--) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}

//^o^
